package com.bite.demospringmvc;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/req")
public class RequestController {
    @RequestMapping("/header")
    public String Header(HttpServletRequest request){
        String header = request.getHeader("User-Agent");
        return "获取到的User-Agent" + header;
    }

    @RequestMapping(value = "/host", method = RequestMethod.GET)
    public String Host(HttpServletRequest request){
        String host = request.getHeader("Host");
        return "获取到达host:" + host;
    }

    @RequestMapping("/header2")
    public String Header2(@RequestHeader("User-Agent") String header){
        return "获取到的User-Agent : " + header;
    }
}
